package com.csi.bumblebee.service.impl;

import com.csi.bumblebee.domain.dictionary.Scale;
import com.csi.bumblebee.mapper.ScaleMapper;
import com.csi.bumblebee.service.ScaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业规模
 * @author yeebs
 */
@Service
public class ScaleServiceImpl implements ScaleService {

    @Autowired
    private ScaleMapper scaleMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 根据id查询企业规模
     * @param id 企业规模主键id
     * @return 企业规模
     */
    @Override
    public Scale findNameById(String id) {
        return scaleMapper.findNameById(id);
    }

    /**
     * 展示所有的企业规模
     * @return List<Scale>
     */
    @Override
    public List<Scale> list() {
        List<Scale> scaleList = (List<Scale>) redisTemplate.opsForValue().get("scaleList");

        if (scaleList != null) {
            return scaleList;
        }else {
            scaleList = scaleMapper.list();
            redisTemplate.opsForValue().set("scaleList", scaleList);
            return scaleList;
        }
    }
}
